import { Module } from 'Vuex'
import http from '@/http/index'
import { api } from '@/http/api'
import GlobalDataProps from '../types'
import { Complaint } from './types'
import { DirtTypeEm } from '@/store/enums'

const system: Module<Complaint, GlobalDataProps> = {
  namespaced: true,
  state: {},
  mutations: {},
  actions: {
    // 投诉列表分页
    handleTransportBillComplaintPage: async ({ commit }, params: any): Promise<any> => {
      let finalResult = ''
      try {
        const result = await http({
          url: api.transportBillComplaintPage,
          method: 'get',
          params
        })
        finalResult = result
      } catch (e) {
        console.log(`ERROR FROM handleTransportBillComplaintPage: ${e}`)
      }
      return finalResult
    },
    // 编辑投诉信息
    handleTransportBillComplaintEdit: async ({ commit }, data: any): Promise<boolean> => {
      let finalResult = false
      try {
        const result = await http({
          url: api.transportBillComplaintEdit,
          method: 'post',
          data
        })
        finalResult = true
      } catch (e) {
        console.log(`ERROR FROM handleTransportBillComplaintEdit: ${e}`)
      }
      return finalResult
    },
    // 查看投诉详情
    handleTransportBillComplaintEetail: async ({ commit }, data: any): Promise<any> => {
      let finalResult = ''
      try {
        const result = await http({
          url: api.transportBillComplaintEetail,
          method: 'post',
          data
        })
        finalResult = result
      } catch (e) {
        console.log(`ERROR FROM handleTransportBillComplaintEetail: ${e}`)
      }
      return finalResult
    },
    // 添加投诉
    handleTransportBillComplaintAdd: async ({ commit }, data: any): Promise<boolean> => {
      let finalResult = false
      try {
        const result = await http({
          url: api.transportBillComplaintAdd,
          method: 'post',
          data
        })
        finalResult = true
      } catch (e) {
        console.log(`ERROR FROM handleTransportBillComplaintAdd: ${e}`)
      }
      return finalResult
    },
    // 模糊查询投诉订单
    handleTransportBillComplaintListBySearch: async ({ commit }, data: any): Promise<any> => {
      let finalResult = ''
      try {
        const result = await http({
          url: api.transportBillComplaintListBySearch,
          method: 'post',
          data
        })
        finalResult = result
      } catch (e) {
        console.log(`ERROR FROM handleTransportBillComplaintListBySearch: ${e}`)
      }
      return finalResult
    },
    // 撤销投诉
    handleTransportBillComplaintRevoke: async ({ commit }, data: any): Promise<boolean> => {
      let finalResult = false
      try {
        const result = await http({
          url: api.transportBillComplaintRevoke,
          method: 'post',
          data
        })
        finalResult = true
      } catch (e) {
        console.log(`ERROR FROM handleTransportBillComplaintRevoke: ${e}`)
      }
      return finalResult
    }
  }
}

export default system
